﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using chad.azure.diagnostics.wad;
using chad.azure.diagnostics.data;
using chad.azure.diagnostics.excel;
using chad.azure.diagnostics.export;

namespace Test.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            String storageAccountName = "";
            String storageAccountKey = "";

            String js = ConfigurationFileProcessor.GenerateReportConfigurationTemplate();
            ReportConfiguration config = ConfigurationFileProcessor.GetReportConfigurationFromJson(js);

            int startMinutesAgo = -60;

            TraceDataSourceProcessor traceProcessor = new TraceDataSourceProcessor(storageAccountName, storageAccountKey, null);
            //PerformanceCounterDataSourceProcessor perfProcess = new PerformanceCounterDataSourceProcessor(storageAccountName, storageAccountKey, null);

            List<Event> traceEvents = traceProcessor.GetEvents(DateTime.UtcNow.AddMinutes(startMinutesAgo), DateTime.UtcNow,3);
            //List<Metric> metrics = perfProcess.GetMetrics(DateTime.UtcNow.AddMinutes(startMinutesAgo), DateTime.UtcNow, null);

            ExcelReportBuilder excel = new ExcelReportBuilder();

            ReportPageSummary summary = new ReportPageSummary() { ObjectName = storageAccountName, StartDateTimeUtc = DateTime.UtcNow.AddMinutes(startMinutesAgo), EndDateTimeUtc = DateTime.UtcNow };
            excel.AddEventSummaryPage("Events Summary", summary, traceEvents, new EventSummaryType[] { EventSummaryType.ByDeploymentByRoleByMessage, EventSummaryType.ByDeploymentByRoleByLevel, EventSummaryType.ByDeploymentByRoleByChannelBySourceByLevel, EventSummaryType.ByDeploymentByRoleByChannelBySourceByLevelByEventId }, @".*");
            excel.AddEventPage("Trace Events","Blah", summary, traceEvents);

            //excel.AddMetricPage("Performance Counters",metrics.ToList());

            excel.ExportReport(String.Format(@"c:\scratch\{0}_{1}.xlsx",storageAccountName,DateTime.Now.ToFileTime().ToString()));

        }
    }
}
